#define _CRT_SECURE_NO_WARNINGS 1

#include<iostream>
#include<vector>
#include<stack>

using namespace std;

vector<int> partitionLabels(string s) {
    vector<int> last(26);
    vector<int> res;
    for (int i = 0; i < s.size(); i++)
        last[s[i] - 'a'] = i;
    int st = 0, end = 0;
    for (int i = 0; i < s.size(); i++)
    {
        end = max(end, last[s[i] - 'a']);
        if (i == end)
        {
            res.push_back(end - st + 1);
            st = end + 1;
        }
    }
    return res;
}

vector<int> dailyTemperatures(vector<int>& t) {
    int n = t.size();
    vector<int> res(n, 0);
    stack<pair<int, int>> s;
    for (int i = 0; i < n; i++)
    {
        while (s.size() && s.top().first < t[i])
        {
            res[s.top().second] = i - s.top().second;
            s.pop();
        }
        s.push({ t[i],i });
    }
    return res;
}